package com.gfwy.proxy;

import java.util.List;

import com.gfwy.dao.IPeriodDao;
import com.gfwy.dao.impl.PeriodDaoImpl;
import com.gfwy.vo.Period;
import com.gfwy.dbc.DatabaseConnection;

public class PeriodDaoProxy implements IPeriodDao {
	IPeriodDao dao = null;
	DatabaseConnection dbc = null;
	public PeriodDaoProxy() {
		try {
			this.dbc = new DatabaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.dao = new PeriodDaoImpl(this.dbc.getConnection());
	}	
	@Override
	public boolean doCreate(Period period) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doCreate(period);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean doUpdate(Period period) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdate(period);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean doDelete(int pid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doDelete(pid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public int count(String keyWords) throws Exception {
		int count;
		try {
			count = this.dao.count(keyWords);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}

	@Override
	public List<Period> findAll(String keyWords, int startIndex, int count)
			throws Exception {
		List<Period> list = null;
		try {
			list = this.dao.findAll(keyWords, startIndex, count);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

	@Override
	public Period findById(int pid) throws Exception {
		Period period = null;
		try {
			period = this.dao.findById(pid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return period;
	}
	@Override
	public boolean doUpdateOrd(int ord, int pid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdateOrd(ord, pid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public List<Period> findLatestPrelude() throws Exception {
		List<Period> list = null;
		try {
			list = this.dao.findLatestPrelude();
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

}
